<?
include('../scaffold/editorial.php');
include('../scaffold/content.php');
include('../scaffold/tag.php');
include('../controller/handler.php');
include('../controller/philomousia.php');

include('../module/var.inc.php');

$hd = new Handler();
$ph = new Philomousia();
$base_url = $hd->getBaseURL();
$hd->openDB();
$tags = $ph->loadTags($hd);
if(count($tags)>0) {
	$num_incipit = $hd->getHomeArticle();
	$contents = array(
		$ph->loadContents($hd, 0, 0, $num_incipit),
		$ph->loadContents($hd, 1, 0, $num_incipit),
		$ph->loadContents($hd, 2, 0, $num_incipit)
	);
	$freq = $ph->getTagFreq($hd);
	$max = max($freq);
}
$editorial = $ph->loadLastEditorial($hd);
$hd->closeDB();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>
	<? include('../module/head.inc.php'); ?>
	<meta name="verify-v1" content="OtCmorIFz5ptE4MH3k7cpxrM9AQL4IozOM5I2aRTfnk=" />
</head>

<body>
<div id="home"></div>
<div id="content">
<?include('../module/header.inc.php');?>

<?if(count($tags)>0) {?>
<div id="sidebar">
<div id="summary" class="article">
	<div class="upper_bar_main"><div class="upper_bar_round"></div></div>
	<div class="body_main_left">
	<div class="body_main_right">
	<div class="body_main">
	<div id="topics">
	<?foreach($tags as $tag) {?>
	<a class="tag_<?echo (int)(5*$freq[$tag->getId()-1]/$max);?>" href="<?echo $base_url;?>tag:<?echo $tag->getId();?>">
		<?echo $tag->getName();?></a> 
	<?}?>
	</div>
	<?$i = 0;
	foreach($contents as $content) {
		foreach($content as $article) {?>
		<div class="small summary_content">
			<p class="summary title"><?echo $article->getTitle();?></p>
			<p class="small details"><?echo strftime($hd->getDateFormat(), strtotime($article->getDate()));?>
				in <a href="<?echo $base_url.$links[$i];?>"><?echo $section[$i];?></a>
			</p>
			<p><?echo substr(strip_tags($hd->makeHTML($article->getBody())), 0, $hd->getIncipitChars());?>...
				<a class="continue" href="<?echo $base_url.$links[$i].'/post:'.$article->getId()?>">(continua)</a>
				<p class="author"><?echo $article->getAuthor();?></p>
			</p>
		</div>
		<?}
		$i++;
	}?>
	</div></div></div>
	<div class="lower_bar_main"><div class="lower_bar_round"></div></div>
</div>
<?if($hd->showCalendar()) {?>
<div id="calendar">
	<div class="upper_bar_main"><div class="upper_bar_round"></div></div>
	<div class="body_main_left">
	<div class="body_main_right">
	<div class="body_main">
	<div id="calendar_body">
	<script type="text/javascript" charset="utf-8">
	//<![CDATA[
	updateCalendar(<?echo time()?>, '<?echo $base_url;?>');
	//]]>
	</script>
	</div>
	</div></div></div>
	<div class="lower_bar_main"><div class="lower_bar_round"></div></div>
</div>
<?}?>
</div>
<?}?>

<?if($editorial) {?>
<div id="editorial" class="article">
	<div class="upper_bar_main"><div class="upper_bar_round"></div></div>
	<div class="body_main_left">
	<div class="body_main_right">
	<div class="body_main">
	<h2><?echo $editorial->getTitle();?></h2>
	<div id="editorial_body">
	<div id="logo"></div>
	<?echo $hd->makeHTML($editorial->getBody());?> &loz;
	<p class="author"><?echo $editorial->getAuthor();?></p>
	</div>
	</div></div></div>
	<div class="lower_bar_main"><div class="lower_bar_round"></div></div>
</div>
<?}?>

<? include('../module/footer.inc.php'); ?>
</div>
<? include('../module/analytics.inc.php'); ?>
</body>
</html>
